/**
 * 
 */
package habitcoach.core.habit.storer;

import habitcoach.core.habit.Habit;
import habitcoach.core.habit.HabitFactory;

import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

/**
 * @author Coddy created on 2010-5-2
 * 
 */
public class HabitSerializableStorerTest
{
	HabitFactory factory;
	HabitSerializableStorer storer;
	List<Habit> list;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		factory = HabitFactory.getInstance();
		storer = HabitSerializableStorer.getInstance();
		list = new ArrayList<Habit>();
	}

	/**
	 * Test method for
	 * {@link habitcoach.core.habit.storer.HabitSerializableStorer#loadHabits(java.lang.String)}
	 * .
	 */
	@Test
	public void testLoadHabits()
	{
		Habit h1 = factory.createHabit("Test1");
		Habit h2 = factory.createHabit("Test2");
		list.add(h1);
		list.add(h2);
		storer.saveHabits(list);

		List<Habit> l = new ArrayList<Habit>();
		l = storer.loadHabits(HabitSerializableStorer.DEFAULT_FILE_NAME);

		Assert.assertEquals(list.size(), l.size());
		Habit h3 = l.get(0);
		Habit h4 = l.get(1);

		Assert.assertEquals(h1.getQuestion(), h3.getQuestion());
		Assert.assertEquals(h1.getStatus(), h3.getStatus());
		Assert.assertEquals(h1.getID(), h3.getID());
	}

}
